#include "cirbuff.h"
#include "protocol.h"

#include <QDebug>

quint8 CirBuff::m_byteBuffer[BUFFER_MAX_LINE] = {0};
quint8 CirBuff::m_writePtr = 0;     //读指针
quint8 CirBuff::m_readPtr = 0;      //写指针

CirBuff::CirBuff(){}

CirBuff::~CirBuff(){}

void CirBuff::writeByte(quint8 byte)
{ 
    m_writePtr %= BUFFER_MAX_LINE;
    m_byteBuffer[m_writePtr++] = byte;
}

quint8 CirBuff::readByte(void)
{
    m_readPtr %= BUFFER_MAX_LINE;
    char readByte = m_byteBuffer[m_readPtr];
    m_byteBuffer[m_readPtr] = 0;
    m_readPtr++;
    return readByte;
}

void CirBuff::traverse_circular_buffer(void)
{
//	char data_n = 0;
//	protocol recvMsg;
//	if(read_circular_buffer() == BGN_RESD_MSG)
//	{
//		recvMsg.potocol_len 	= read_circular_buffer();
//		recvMsg.device_cmd    = read_circular_buffer();
//		recvMsg.data_len      = read_circular_buffer();
			
//		if(recvMsg.data_len > 0)
//		{
//			recvMsg.data = (char *)malloc(sizeof(char)*recvMsg.data_len);
//			for(data_n = 0; data_n < recvMsg.data_len; data_n++)
//			{
//				recvMsg.data[data_n] = read_circular_buffer();
//			}
//		}else
//		{
//				read_circular_buffer();
//		}
			
//		if(read_circular_buffer() == END_RESD_MSG)
//		{
//			recv_data(&recvMsg);
//		}
//	}
}
